package com.lagou.rpcprovider;

import com.alibaba.druid.pool.DruidDataSource;
import org.I0Itec.zkclient.ZkClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author zhangxuyuan
 * @version 1.0
 * @date 2020/11/29
 */
//@Configuration
public class DataSourceConfig {

    @Bean
    public DataSource dataSource(ZkClient zkClient)
    {   //获取注册中心数据
        String url = zkClient.readData("/zk-config/url");
        String username = zkClient.readData("/zk-config/username");
        String password = zkClient.readData("/zk-config/password");
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }

}
